package top.eggcode.modules.dict.store;

import org.springframework.stereotype.Repository;
import top.eggcode.component.query.CriteriaBuilder;
import top.eggcode.component.query.model.PageList;
import top.eggcode.modules.dict.model.WordEntity;
import top.eggcode.modules.dict.model.WordQuery;

import javax.annotation.Resource;

/**
 * Title:
 * Description: TODO
 * Date: 2021/9/19 11:28
 *
 * @author JiaQi Ding
 * @version 1.0
 */
@Repository
public class WordStore {

    @Resource
    private CriteriaBuilder builder;

    public PageList<WordEntity> page(WordQuery query) {
        return builder.createQuery(WordEntity.class)
                .select("*")
                .from("system_word")
                .where(condition -> {
                    if (query.getDictId() != null) {
                        condition.eq("dict_id", query.getDictId());
                    }
                })
                .orderBy("sequence")
                .fetchPage(query);
    }

}
